import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'
import { formatBytes } from '@/utils'

import api from '@/api'
const { listNamespaced } = api

// 工作负载列表
export function getWorkloadBasicColumns(): BasicColumn[] {
  return [
    {
      title: '工作负载名称',
      width: 160,
      dataIndex: 'name'
    },
    {
      title: '运行环境',
      width: 80,
      dataIndex: 'nameType'
    },
    {
      title: '状态',
      width: 80,
      dataIndex: 'status'
    },
    {
      title: '实例个数(正常/全部)',
      width: 150,
      dataIndex: 'replicas'
    },
    {
      title: '端口号',
      align: 'right',
      width: 80,
      dataIndex: 'port'
    },
    {
      title: '命名空间',
      width: 160,
      dataIndex: 'namespace'
    },
    {
      title: '镜像名称',
      width: 320,
      dataIndex: 'image'
    },
    {
      title: '创建时间',
      width: 130,
      customEllipsis: true,
      dataIndex: 'creationTimestamp'
    },
    {
      title: '操作',
      width: 120,
      dataIndex: 'operate'
    }
  ]
}
// 工作负载列表详情
export function getDetailBasicColumns(): BasicColumn[] {
  return [
    {
      title: '实例名称',
      width: 260,
      customEllipsis: true,
      dataIndex: 'name'
    },
    {
      title: '状态',
      dataIndex: 'status'
    },
    {
      title: '命名空间',
      width: 160,
      dataIndex: 'namespace'
    },
    {
      title: '实例IP',
      dataIndex: 'podIp'
    },
    {
      title: '所在节点',
      dataIndex: 'hostIp'
    },
    {
      title: '重启次数',
      align: 'right',
      dataIndex: 'restartCount'
    },
    {
      title: 'CPU申请值',
      dataIndex: 'cpu',
      format: (text) => {
        return text ? `${text} Cores` : ''
      }
    },
    {
      title: '内存申请值',
      dataIndex: 'memory',
      format: (text) => {
        return formatBytes(text)
      }
    },
    {
      title: '创建时间',
      dataIndex: 'creationTimestamp'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    baseColProps: {
      span: 6,
      md: 10,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: 'name',
        label: '负载名称',
        component: 'Input'
      },
      {
        field: 'namespace',
        label: '命名空间',
        component: 'ApiSelect',
        componentProps: {
          api: listNamespaced,
          resultField: 'result.list',
          labelField: 'name',
          valueField: 'name',
          immediate: true
        }
      }
    ]
  }
}
